const { log, error } = require('console');
const express = require('express');
const router = express.Router()
const multerUpload = require('../utils/multerUpload');
const path = require('path');

// /_token/upload  /upload/rich_editor_upload
router.post('/_token/upload',
    (req, res, next) => { multerUpload.array('files'), next() },
    (req, res) => {
        let { files } = req
        let filesUrl = files[0].destination + files[0].filename
        console.log(filesUrl);
        log('files:', req.files)
        if (files.length) {
            // code: 200, msg: '上传成功', filesCount: files.length,
            res.send({
                errno: 0,
                data: {
                    // url: files.map(item => item.destination + item.filename), // 图片 src ，必须
                    url: filesUrl // 图片 src ，必须
                }
            });
        } else {
            res.send({ code: 500, errno: 1, msg: '上传失败', });
        }
    })

module.exports = router